package com.vshining.cryptoki.jna.pkcs11t;

import com.sun.jna.NativeLong;
import com.sun.jna.Structure;

import java.util.Arrays;
import java.util.List;

/**
 * * @author Shining Wang <shiningwang@vshining.com>
 */
@SuppressWarnings("unused")
public class CK_TOKEN_INFO extends Structure {
    public byte[] label = new byte[32];
    public byte[] manufacturerID = new byte[32];
    public byte[] model = new byte[16];
    public byte[] serialNumber = new byte[16];
    public NativeLong flags;
    public NativeLong ulMaxSessionCount;
    public NativeLong ulSessionCount;
    public NativeLong ulMaxRwSessionCount;
    public NativeLong ulRwSessionCount;
    public NativeLong ulMaxPinLen;
    public NativeLong ulMinPinLen;
    public NativeLong ulTotalPublicMemory;
    public NativeLong ulFreePublicMemory;
    public NativeLong ulTotalPrivateMemory;
    public NativeLong ulFreePrivateMemory;
    public CK_VERSION hardwareVersion;
    public CK_VERSION firmwareVersion;
    public byte[] utcTime = new byte[16];

    @Override
    protected List getFieldOrder() {
        return Arrays.asList(
                "label",
                "manufacturerID",
                "model",
                "serialNumber",
                "flags",
                "ulMaxSessionCount",
                "ulSessionCount",
                "ulMaxRwSessionCount",
                "ulRwSessionCount",
                "ulMaxPinLen",
                "ulMinPinLen",
                "ulTotalPublicMemory",
                "ulFreePublicMemory",
                "ulTotalPrivateMemory",
                "ulFreePrivateMemory",
                "hardwareVersion",
                "firmwareVersion",
                "utcTime"
        );
    }

    public static final long CKF_RNG  = 0x00000001L;
    public static final long CKF_WRITE_PROTECTED  = 0x00000002L;
    public static final long CKF_LOGIN_REQUIRED  = 0x00000004L;
    public static final long CKF_USER_PIN_INITIALIZED  = 0x00000008L;
    public static final long CKF_RESTORE_KEY_NOT_NEEDED  = 0x00000020L;
    public static final long CKF_CLOCK_ON_TOKEN  = 0x00000040L;
    public static final long CKF_PROTECTED_AUTHENTICATION_PATH  = 0x00000100L;
    public static final long CKF_DUAL_CRYPTO_OPERATIONS  = 0x00000200L;
    public static final long CKF_TOKEN_INITIALIZED  = 0x00000400L;
    public static final long CKF_SECONDARY_AUTHENTICATION  = 0x00000800L;
    public static final long CKF_USER_PIN_COUNT_LOW  = 0x00010000L;
    public static final long CKF_USER_PIN_FINAL_TRY  = 0x00020000L;
    public static final long CKF_USER_PIN_LOCKED  = 0x00040000L;
    public static final long CKF_USER_PIN_TO_BE_CHANGED  = 0x00080000L;
    public static final long CKF_SO_PIN_COUNT_LOW  = 0x00100000L;
    public static final long CKF_SO_PIN_FINAL_TRY  = 0x00200000L;
    public static final long CKF_SO_PIN_LOCKED  = 0x00400000L;
    public static final long CKF_SO_PIN_TO_BE_CHANGED  = 0x00800000L;

}
